package org.ruanjj.stringtransformation;

public class Solution {
    public String stringTransformation(String message){
        StringBuilder stringBuilder = new StringBuilder();
        String[] splitMessage = message.trim().split(" ");
        for(int i=splitMessage.length-1; i >= 0; i--){
            for(int j=0; j<splitMessage[i].length(); j++){
                if(splitMessage[i].charAt(j) != ' '){
                    if(Character.isLowerCase(splitMessage[i].charAt(j))){
                        stringBuilder.append(Character.toUpperCase(splitMessage[i].charAt(j)));
                    }else if(Character.isUpperCase(splitMessage[i].charAt(j))){
                        stringBuilder.append(Character.toLowerCase(splitMessage[i].charAt(j)));
                    }
                }
            }
            stringBuilder.append(" ");
        }
        return  stringBuilder.toString().trim();
    }
}
